<template>
  <div class="detail" >
    {{detailData.name}}
    {{detailData.context}}
    <van-button type="warning" @click="$router.go(-1)">返回</van-button>
    <van-button type="primary" v-if='!detailData.isAdd' @click="toCart()">加入购物车</van-button>
  </div>
</template>

<script>
import { mapState,mapMutations } from "vuex";
export default {
  computed: {
    ...mapState(["bookList"]),
    detailData() {
      return this.bookList.filter(v => {
        return v.id === this.$route.params.id;
      })[0];
    }
  },
  created() {
    console.log(this.$route.params.id);
  },
  methods: {
    ...mapMutations(['addToCart']),
    toCart() {
      this.addToCart(this.detailData)
    }
  }
};
</script>

<style>
</style>